﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


/* ***********************************************
 * subject  
 * author   张勇
 * date     2019/8/14 15:10:59 
 * ***********************************************/

namespace Weight.Controls
{
    public class LYFMenuTreeView : Control
    {
        public LYFMenuTreeView()
        {
            this.SetStyle(
                     //ControlStyles.UserPaint |//使用自定义的绘制方式
                     ControlStyles.ResizeRedraw//当控件大小发生变化时就重新绘制
                    | ControlStyles.SupportsTransparentBackColor//则控件接受 alpha 组件数小于 255 个的 BackColor 来模拟透明度
                    | ControlStyles.AllPaintingInWmPaint//则控件忽略窗口消息 WM_ERASEBKGND 以减少闪烁
                    | ControlStyles.OptimizedDoubleBuffer//则控件将首先绘制到缓冲区而不是直接绘制到屏幕，这可以减少闪烁
                    , true);

            Nodes = new Dictionary<CoolMenuInfo, List<CoolMenuInfo>>();
        }

        public EventHandler<CoolMenuEventArgs> NodeClick;

        private Dictionary<CoolMenuInfo, List<CoolMenuInfo>> _nodes;
        //[System.ComponentModel.Browsable(true)]
        [Description("菜单项属性列表"), Category("自定义属性")]
        public Dictionary<CoolMenuInfo, List<CoolMenuInfo>> Nodes
        {
            get => _nodes;
            set
            {
                _nodes = value;
                if (_nodes != null)
                    this.Invalidate();

            }
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            foreach (var n1 in _nodes)
            {
                if (n1.Value == null) continue;



                foreach (CoolMenuInfo n2 in n1.Value)
                {

                }
            }


            base.OnPaint(e);
        }


        protected override void OnMouseClick(MouseEventArgs e)
        {
            Point pt = new Point(e.X, e.Y);



            base.OnMouseClick(e);
        }
    }
    [Serializable]
    public class CoolMenuInfo : ISerializable
    {
        public string Text { get; set; }
        public Image Image { get; set; }
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {

        }
    }

    public class CoolMenuEventArgs : EventArgs
    {
        public int Index { get; set; }
        public int Level { get; set; }
        public Rectangle Bounds { get; set; }
        public CoolMenuInfo CoolMenuInfo { get; set; }
    }
}
